package com.fm.openinstall;

import com.fm.openinstall.f.*;
import com.fm.openinstall.model.*;
import java.io.*;
import com.fm.openinstall.listener.*;
import android.content.*;
import android.text.*;

public class OpenInstall
{
    private static a a;
    private static volatile boolean b = false;

    private OpenInstall() {
    }

    private static boolean a() {
        if (!OpenInstall.b) {
            if (com.fm.openinstall.f.b.a) {
                com.fm.openinstall.f.b.c("\u8bf7\u5148\u8c03\u7528 init(Context) \u521d\u59cb\u5316", new Object[0]);
            }
            return false;
        }
        return true;
    }

    public static boolean checkYYB(final Intent intent) {
        return OpenInstall.a.b(intent);
    }

    @Deprecated
    public static void destoryInstall() {
        OpenInstall.a.c();
    }

    public static void getInstall(final AppInstallListener appInstallListener) {
        getInstall(appInstallListener, 0);
    }

    public static void getInstall(final AppInstallListener appInstallListener, final int n) {
        if (!a()) {
            appInstallListener.onInstallFinish(null, null);
            return;
        }
        if (isValidInstall()) {
            OpenInstall.a.a(appInstallListener, n);
            return;
        }
        appInstallListener.onInstallFinish(null, null);
    }

    public static void getUpdateApk(final GetUpdateApkListener getUpdateApkListener) {
        if (!a()) {
            getUpdateApkListener.onGetFinish(null);
            return;
        }
        OpenInstall.a.a(getUpdateApkListener);
    }

    public static boolean getWakeUp(final Intent intent, final AppWakeUpListener appWakeUpListener) {
        if (!a()) {
            return false;
        }
        if (isValidIntent(intent)) {
            OpenInstall.a.a(intent, appWakeUpListener);
            return true;
        }
        return false;
    }

    public static boolean getWakeUpYYB(final Intent intent, final AppWakeUpListener appWakeUpListener) {
        if (!a()) {
            return false;
        }
        if (checkYYB(intent)) {
            OpenInstall.a.a(appWakeUpListener);
            return true;
        }
        return false;
    }

    public static void init(final Context context) {
        init(context, com.fm.openinstall.a.a.a(context, "com.openinstall.APP_KEY"));
    }

    public static void init(Context applicationContext, final String s) {
        if (applicationContext != null) {
            if (!TextUtils.isEmpty((CharSequence)s)) {
                if (com.fm.openinstall.f.b.a) {
                    com.fm.openinstall.f.b.a("SDK VERSION : %s", "2.2.2");
                }
                synchronized (OpenInstall.class) {
                    if (!OpenInstall.b) {
                        applicationContext = applicationContext.getApplicationContext();
                        if (OpenInstall.a == null) {
                            OpenInstall.a = new a(applicationContext, s);
                        }
                        OpenInstall.b = true;
                    }
                    return;
                }
            }
            throw new IllegalArgumentException("\u8bf7\u5728AndroidManifest.xml\u4e2d\u914d\u7f6eOpenInstall\u63d0\u4f9b\u7684AppKey");
        }
        throw new IllegalArgumentException("context\u4e0d\u80fd\u4e3a\u7a7a");
    }

    @Deprecated
    public static boolean isValidInstall() {
        return OpenInstall.a.b();
    }

    public static boolean isValidIntent(final Intent intent) {
        return OpenInstall.a.a(intent);
    }

    public static void reportEffectPoint(final String s, final long n) {
        if (!a()) {
            return;
        }
        OpenInstall.a.a(s, n);
    }

    public static void reportRegister() {
        if (!a()) {
            return;
        }
        OpenInstall.a.a();
    }

    public static void setDebug(final boolean a) {
        com.fm.openinstall.f.b.a = a;
    }
}
